package com.wandian.ui.skins
{
	import flash.display.Graphics;

	import com.wandian.utils.ColorUtil;
	import com.wandian.utils.Const;

	public class ScrollThumbSkin extends Skin
	{
		public function ScrollThumbSkin()
		{
			super();
		}

		override public function updateDisplay(w:int, h:int, state:String,...args):void
		{

			var borderColor:int=getStyle("borderColor");
			var borderDarkColor:int=ColorUtil.adjustBrightness(borderColor, -25)
			var radius:int=getStyle("cornerRadius");
			var borderColors:Array=[borderColor, borderDarkColor]
			var fillAlphas:Array=getStyle("fillAlphas");
			var fillColors:Array=getStyle("fillColors");
			var highlightAlphas:Array=getStyle("highlightAlphas");
			var themeColor:int=getStyle("themeColor");
			var themeDarkColor:int=ColorUtil.adjustBrightness(themeColor, -25);

			var g:Graphics=this.graphics
			g.clear();

			g.beginFill(0xFFFFFF, 0)
			g.drawRect(0, 0, w, h)
			w-=2

			switch (state)
			{

				case "over":
				{
					var overFillColors:Array=[fillColors[2], fillColors[3]];
					var overFillAlphas:Array=[fillAlphas[2], fillAlphas[3]];

					//border
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 0)
					g.beginGradientFill("linear", [themeColor, themeDarkColor], Const.fullAlpha, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 0, w, h, 0, radius, 0, radius)

					w--
					h-=2
					radius--
					g.drawRoundRectComplex(1, 1, w, h, 0, radius, 0, radius)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", overFillColors, overFillAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, 0, radius, 0, radius)
					g.endFill()
					// top highlight
					h/=2
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", [0xFFFFFF, 0xFFFFFF], highlightAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, 0, radius, 0, radius)
					break;
				}
				case "down":
				{
					var downFillColors:Array=[ColorUtil.adjustBrightness(themeColor, 85), ColorUtil.adjustBrightness(themeColor, 60)];
					//border
					g.beginFill(themeColor, 1)
					g.drawRoundRectComplex(1, 0, w, h, 0, radius, 0, radius)

					w--
					h-=2
					radius--
					g.drawRoundRectComplex(1, 1, w, h, 0, radius, 0, radius)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", downFillColors, Const.fullAlpha, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, 0, radius, 0, radius)
					g.endFill()
					// top highlight
					h/=2
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", [0xFFFFFF, 0xFFFFFF], highlightAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, 0, radius, 0, radius)
					break;
				}
				case "disabled":
				{
					var disabledFillColors:Array=[fillColors[0], fillColors[1]];
					var disabledFillAlphas:Array=[fillAlphas[0] - 0.15, fillAlphas[1] - 0.15];

					//border
					g.beginFill(borderColor, 0.5)
					g.drawRect(0, 0, w, h)
					w-=2
					h-=2

					g.drawRect(1, 1, w, h)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", disabledFillColors, disabledFillAlphas, Const.fullRatio, Const.matrix)
					g.drawRect(1, 1, w, h)
					g.endFill()
					break;
				}
				default:
				{
					var upFillColors:Array=[fillColors[0], fillColors[1]];
					var upFillAlphas:Array=[fillAlphas[0], fillAlphas[1]];

					//border
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 0)
					g.beginGradientFill("linear", borderColors, Const.fullAlpha, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 0, w, h, 0, radius, 0, radius)

					w--
					h-=2
					radius--
					g.drawRoundRectComplex(1, 1, w, h, 0, radius, 0, radius)
					g.endFill()
					//body
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", upFillColors, upFillAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, 0, radius, 0, radius)
					g.endFill()
					// top highlight
					h/=2
					Const.matrix.createGradientBox(w, h, Const.PI_2, 1, 1)
					g.beginGradientFill("linear", [0xFFFFFF, 0xFFFFFF], highlightAlphas, Const.fullRatio, Const.matrix)
					g.drawRoundRectComplex(1, 1, w, h, 0, radius, 0, radius)
					break;
				}

			}
			var x:int=Math.floor(w / 2) - 2;
			var y:int=h
			g.beginFill(0x000000, 0.4)
			g.drawRect(x, y - 4, 5, 1)
			g.drawRect(x, y - 2, 5, 1)
			g.drawRect(x, y, 5, 1)
			g.drawRect(x, y + 2, 5, 1)
			g.drawRect(x, y + 4, 5, 1)

			g.endFill()

		}

	}
}
